<template>
  <div style="padding: 10px">
    <div style="margin: 10px 0">
      <el-input v-model="page.param.teamlog_name" placeholder="请输入团队日志标题" style="width: 20%" clearable></el-input>
      <el-button type="primary" style="margin-left: 5px" @click="load">搜索</el-button>
      <el-button type="info" style="margin-left: 5px" @click="reset">重置</el-button>
<!--      <el-button type="warning" style="padding-right:10px" @click="add">新增</el-button>-->
    </div>
    <el-table :data="state.tableData" border style="width: AUTO" :header-cell-style="{
      background:'#b1b3b8',height:'50px',color:'#000000',border: '1px solid tan'}">
      <el-table-column prop="teamlogId" label="团队日志ID" width="100"/>
      <el-table-column prop="teamlogName" label="团队日志标题" style="width: AUTO" />
      <el-table-column prop="teamId" label="团队ID" style="width: AUTO" />
      <el-table-column prop="teamlogDate" label="团队日志提交日期" style="width: AUTO" />
      <el-table-column prop="teamlogContent" label="团队日志内容" style="width: AUTO" />
      <el-table-column prop="teamComment" label="团队评论" style="width: AUTO" />
      <el-table-column prop="teamLogState" label="日志状态" style="width: AUTO" />
      <el-table-column label="操作" >
        <template #default="scope">
          <el-button  type="primary" @click="handleEdit(scope.row)">评论</el-button>
<!--          <el-popconfirm title="确认删除吗？" @confirm="handleDelete(scope.row.teamlogId)">-->
<!--            <template #reference>-->
<!--              <el-button  type="danger" >删除</el-button>-->
<!--            </template>-->
<!--          </el-popconfirm>-->
        </template>
      </el-table-column>
    </el-table>

    <div style="padding: 10px">
      <el-pagination
          background
          v-model:current-page="page.pageNum"
          v-model:page-size="page.pageSize"
          :page-sizes="[5, 10, 15]"
          large
          :disabled="false"
          layout="total, sizes, prev, pager, next, jumper"
          :total="state.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>

    <el-dialog v-model="dialogVisible" title="团队日志信息" width="40%" height="200px">
      <el-form label-width="140px" :model="state.form" >
<!--        <el-form label-width="140px" :model="state.form" :rules="state.rules" ref="rulesFormRef">-->
<!--        <el-form-item prop="teamlogName" label="团队日志标题" >-->
<!--          <el-input v-model="state.form.teamlogName" placeholder="请输入团队日志标题" style="width: 80%" />-->
<!--        </el-form-item>-->

        <el-form-item prop="teamComment" label="团队日志内容">
          <el-input type="textarea" :rows="8" resize="none" v-model="state.form.teamComment" placeholder="请输入评论" style="height:260px; width: 80%"/>
        </el-form-item>


      </el-form>
      <template #footer>
            <span class="dialog-footer">
              <el-button @click="dialogVisible = false">取消</el-button>
              <el-button type="primary" @click="save">确定</el-button>
            </span>
      </template>
    </el-dialog>
  </div>
</template>




<script setup>
import {getCurrentInstance, reactive, ref} from "vue";
import request from "@/request";
import {ElMessage, ElNotification} from "element-plus";

const { proxy }=getCurrentInstance()

const kk = reactive({
  form:{},
})
kk.form=localStorage.getItem("student") ? JSON.parse(localStorage.getItem("student")) : {}

const load = () => {
  request.post('/teamlog/listPage',JSON.stringify(page)).then(res=>{
    if(res.code===200) {
      state.tableData = res.data
      state.total=res.total
    }
  })
}

const page=reactive({
  pageNum:ref(1),
  pageSize:ref(10),
  param:{
    // team_id:ref(kk.form.teamId),
    teamlog_name:ref()
  }
})
//刷新页面
load()
//页数
const handleSizeChange=(val)=>{
  page.pageSize=val
  load()
}
//每页数量
const handleCurrentChange=(val)=>{
  page.pageNum=val
  load()
}

const reset=()=>{
  page.param.teamlog_name="";
  load()
}

const dialogVisible=ref(false)

// const add=()=>{
//   dialogVisible.value=true;
//   state.form={
//     teamId:kk.form.teamId,
//     teamlogDate:new Date().toLocaleString(),
//     teamLogState:"未评论",
//     teamComment:"无"
//   }
//
// }
const handleEdit=(row)=>{

  state.form=JSON.parse(JSON.stringify(row))
  state.form.teamComment=""

  dialogVisible.value=true;
}
const save=()=>{
      if(state.form.teamComment){
        state.form.teamLogState="已评论"

        request.post('/teamlog/update',JSON.stringify(state.form)).then(res=>{
          if(res.code===200){
            ElNotification({
              type:"success",
              message:"评论成功"
            })
            dialogVisible.value=false;
            load();
          }
        })
      }else{
        ElMessage({
          type:"error",
          message:'请填写评论'
        })
      }
}

// const handleDelete=(teamId)=>{
//   request.get('/teamlog/del',{params:{teamlog_id:teamId}}).then(res=>{
//     if(res.code===200){
//       ElNotification({
//         type:"success",
//         message:"删除成功"
//       })
//       load()
//     }
//   })
// }


//数据
const state = reactive({
  tableData: [],
  total:0,
  form:{},
  // rules:{
  //   teamlogName: [
  //     { required: true, message: '请输入团队日志标题', trigger: 'blur' },
  //   ],
  //   teamId: [
  //     { required: true, message: '请输入学生所在团队ID', trigger: 'blur' },
  //   ],
  //   teamlogDate: [
  //     { required: true, message: '请输入团队日志提交日期', trigger: 'blur' },
  //   ],
  //   teamlogContent: [
  //     { required: true, message: '请输入团队日志内容', trigger: 'blur' },
  //   ],
  //   teamComment: [
  //     { required: true, message: '请输入团队评论', trigger: 'blur' },
  //   ],
  //   teamLogState: [
  //     { required: true, message: '请输入团队日志状态', trigger: 'blur' },
  //   ],
  // }
})
</script>


<style>
</style>
